package org.example;

import org.testng.Assert;
import org.testng.annotations.Test;

public class TestHelloWorld {

    // 测试返回结果不为空
    @Test
    public void tester1(){
        HelloWorld hello = new HelloWorld();
        String helloworld = hello.hello();
        // 检查返回结果
        Assert.assertNotNull(helloworld);
    }

    @Test(groups = "demo-1")
    public void tester_group_1(){
        HelloWorld hello = new HelloWorld();
        String helloworld = hello.hello();
        // 检查返回结果
        Assert.assertNotNull(helloworld);
    }

    // 超时测试,超过配置时间 即测试不通过
    @Test(timeOut = 2000) //单位毫秒
    public void tester_time() throws InterruptedException {
        Thread.sleep(5000);
    }


    @Test(enabled = false,expectedExceptions = ArithmeticException.class)
    //抛出ArithmeticException 异常算测试完成
    //也可以是 异常组 @Test(expectedExceptions = {ClassName.class, ClassName2.class,... })
    public void tester_expect(){
        HelloWorld hello = new HelloWorld();
        String helloworld = hello.hello();
        // 检查返回结果
        Assert.assertNotNull(helloworld);
    }

    // 测试返回结果为"hello world!"字符串,enabled =false 运行时不会执行
    @Test(enabled = false)
    public void tester2(){
        HelloWorld hello = new HelloWorld();
        String helloworld = hello.hello();
        System.out.println(helloworld);
        // 检查返回结果是否=hello world!
        Assert.assertEquals(helloworld,"Hello world!");
    }


    // 依赖方法,当 ref 方法执行通过后，才会调用methodName1 和 methodName2 方法 失败即停止
    @Test(dependsOnMethods = { "methodName1" ,"methodName2" })
    public void tester_ref_function() throws InterruptedException {
        System.out.println("测试方法tester1");
    }

    @Test
    public void methodName1(){
        System.out.println("依赖方法methodName1");
    }

    @Test
    public void methodName2(){
        System.out.println("依赖方法methodName2");
    }

}
